package com.java110.mall.shop.cmd.shop;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.community.CommunityDto;
import com.java110.mall.shop.bmo.shopCommunity.IGetShopCommunityBMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

@Java110Cmd(serviceCode = "shop.queryShopFreeCommunity")
public class QueryShopFreeCommunityCmd extends Cmd {


    @Autowired
    private IGetShopCommunityBMO getShopCommunityBMOImpl;

    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        super.validatePageInfo(reqJson);
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        CommunityDto communityDto = BeanConvertUtil.covertBean(reqJson,CommunityDto.class);
        communityDto.setCityCode(reqJson.getString("areaCode"));
        String shopType = reqJson.getString("shopType");
        if (!StringUtil.isEmpty(shopType) && shopType.contains(",")) {
            communityDto.setShopTypes(shopType.split(","));
        } else {
            communityDto.setShopType(shopType);
        }

        ResponseEntity<String> responseEntity = getShopCommunityBMOImpl.getFreeCommunitys(communityDto);
        context.setResponseEntity(responseEntity);
    }
}
